// _compoments/normalRoom/scrollPosterWallView/scrollPosterWallView.js
const app = getApp();
import TWEEN from './../../../pages/normalRoom/tween.js';

Component({
        /**
         * 组件的属性列表
         */
        properties: {
                posterImageData: {
                        type: Array,
                        value: [],
                },
                backgroundImage: {
                        type: String,
                        value: "",
                },

                posterBigScreenWallWidth:  {
                        type: Number,
                        value: "100",
                },

                posterSmallScreenWallWidth:  {
                        type: Number,
                        value: "100",
                },

                scrollBigScreenStartLeft:  {
                        type: Number,
                        value: "100",
                },

                scrollSmallScreenStartLeft:  {
                        type: Number,
                        value: "100",
                },
        },

        /**
         * 组件的初始数据
         */
        data: {
                baseUrl: app.globalData.baseUrl,
                posterMoveToBottom: true,

                tipImage: '',
                scrolledPostion: '749rpx',

                scrollWidth: "100rpx",
        },

        attached() {
                let tempWidth = (app.globalData.deviceAspectRatio >= 0.5 ? 
                        this.data.posterSmallScreenWallWidth : this.data.posterBigScreenWallWidth)
                
                this.setData({
                        scrollWidth: tempWidth
                })

                setTimeout(() => {
                        this.setData({
                                // scrolledPostion: app.globalData.deviceAspectRatio >= 0.5 ? "520rpx" : "565rpx"
                                scrolledPostion: (app.globalData.deviceAspectRatio >= 0.5 ? 
                                         this.data.scrollSmallScreenStartLeft : this.data.scrollBigScreenStartLeft)
                        }) 
                }, 200);
     
                // var that = this;

                // var intervalId = setInterval(function () {
                //     TWEEN.update();
                //   }, 30);  

                //   var videoData = this.data.posterImageData;
                //   var topArray = [];
 
                //   const res = wx.getSystemInfoSync();
                //   for(var i=0; i<this.data.posterImageData.length; i++)
                //   {
                //       topArray.push(parseFloat(this.data.posterImageData[i].top)*res.windowHeight*0.02);
                //   }

                //   var coords = {
                //     x: 0,
                //   };
                //   new TWEEN.Tween(coords)
                //     .to(
                //       {
                //         x: 15,
                //       },
                //       5.2 * 1000
                //     )
                //     .yoyo(true)
                //     .repeat(Infinity)
                //     .easing(TWEEN.Easing.Linear.None)
                //     .onUpdate(function () { 
                //         //var num = Math.round(coords.x);
                //         var num = coords.x;

                //         videoData[1].top = topArray[1] + num;
                //         videoData[3].top = topArray[3] + num;
                //         videoData[5].top = topArray[5] + num;
                //         videoData[6].top = topArray[6] + num;
         
                //         videoData[0].top = topArray[0] - num;
                //         videoData[2].top = topArray[2] - num ;
                //         videoData[4].top = topArray[4] - num;

                //         that.setData({
                //             posterImageData: videoData
                //         })
                //     })
                //     .onComplete(function () {})
                //     .delay(0)
                //     .start();
                  
        },

        /**
         * 组件的方法列表
         */
        methods: {
                onPosterClick(e) {
                        // console.log(e)
                        let tempData = e.currentTarget.dataset.item;

                        this.triggerEvent("onPosterClick", tempData);
                },

                changePosterRootPosition(e) {
                        console.log("changePosterRootPosition " + e)
                        this.setData({
                                posterMoveToBottom: e
                        })
                },

                onTipClick(e) {
                        let tempData = e.currentTarget.dataset.item;
                        app.saveTrack(`视频标签 - room${app.globalData.gCurrentRoomIndex} - ${tempData.orderNo}`);
                        this.triggerEvent("showVideoTip", tempData.videoDescUrl);
                }
        },
})